#include<iostream>
using namespace std;
int dp[31][20010];
int main()
{
    int v = 0, n = 0;
    int arr[20010];
    cin >> v >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= v; j++)
        {
            if (j >= arr[i])
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - arr[i]] + arr[i]);
            }
            dp[i][j] = dp[i - 1][j];
        }
    }
    cout << v - dp[n][v] << endl;
    return 0;
}